blackImg=  new Image();
blackImg.src="images/black.jpg";
whiteImg=  new Image();
whiteImg.src="images/bg.jpg";
darkImg=  new Image();
darkImg.src="images/dark.jpg";
yellowImg=  new Image();
yellowImg.src="images/yellow.jpg";
redImg=  new Image();
redImg.src="images/red.jpg";
/**
 * 创建蛇 
 * @param {Object} 游戏总控制对象
 * @param {Object} type 类型  0为最后一排  1为123排
 * @param {Object} x 
 * @param {Object} y
 * @param {Object} w    每个块的宽
 * @param {Object} h	每个块的高
 * @param {Object} color　white  black
 */
Block =function(game,type,x,y,w,h,color)
{
//	console.log(game);
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.game = game;
	this.type= type;
	this.color = color;
	this.img =[];
	
	this.__init=function(){
//		console.log(this.color);
		this.img= this.getImage();
	}
	//获取块的贴图
	this.getImage=function()
	{
	var img = [];
		for(var i=0;i<4;i++){
			if(this.type!=0)
			{
				switch(this.color[i]){
					case 'black':
					img.push(blackImg);
//					img[i] =;
					break;
					case 'white':
					img.push(whiteImg);
//					img[i] =whiteImg;
					break;
				}
			}else{
				img.push(yellowImg);
//				img[i] =darkImg;
			}	
		}
		return img;
	}
	//将自己画到画板中
	this.draw=function(){
		for(var x=0;x<4;x++){
//			console.log(x);
			this.game.canvas.drawImage(this.img[x],(x*this.w),(this.y*this.h),this.w,this.h);
			this.game.canvas.strokeStyle='#000';
			this.game.canvas.lineWidth=0.5;
			this.game.canvas.strokeRect((x*this.w),(this.y*this.h),this.w,this.h);
		}
		
	}
//	绘制单个块
	this.drawOne=function(x,y){
//		console.log(x);
//		console.log(y);
		
		this.game.canvas.drawImage(this.img[x],(x*this.w),(y*this.h),this.w,this.h);
	}
//	执行自身的函数
	this.__init();
}








